<template>
  <div id="app">
    <!-- 头部区域 -->
    <Topbar :key="topBarKey"></Topbar>
    <!-- 头部导航部分 -->
    <Header></Header>
    <!-- 内容区域 -->
    <!-- <Toast1></Toast1> -->
    <router-view @Cartfn="topCart" />
    <login v-show="isShowloginModal"></login>
    <!-- 控制弹出狂 -->
    <transition name="slide">
      <Toast1 v-show="isShowToast"></Toast1>
    </transition>
    <!-- 底部区域 -->
    <Footer></Footer>
  </div>
</template>
<script>
import Topbar from "@/components/Topbar.vue";
import Header from "@/components/Header.vue";
import Footer from "@/components/Footer.vue";
import Toast1 from "@/components/Toast1.vue";
// import axios from "@/request/request";
import { JinpApi, HotApi } from "@/request/api";
import login from "@/components/login.vue";
import { mapState } from "vuex";
// import showModal from "./store/showModal";
export default {
  data() {
    return {
      topBarKey: 1,
    };
  },
  components: { Topbar, Header, Footer, login, Toast1 },
  async created() {
    let res1 = await JinpApi();
    // console.log("res1精品推荐：", res1);
    let res2 = await HotApi();
    // console.log("res2热门推荐：", res2);
  },
  computed: {
    ...mapState({
      isShowloginModal: (state) => state.showModal.isShowloginModal,
      // 弹框的
      isShowToast: (state) => state.showToast.isShowToast,
    }),
  },
  // 监听路由地址的变化
  watch: {
    "$route.path": {
      handler(newVal, oldVal) {
        if (newVal !== oldVal) {
          // console.log("....key已经发生变化了");
          this.topBarKey++;
        }
      },
    },
  },
  methods: {
    topCart() {
      this.topBarKey++;
    },
  },
};
</script>
<style lang="less">
.slide-enter,
.slide-leave-to {
  opacity: 0;
}

.slide-enter-active,
.slide-leave-active {
  transition: opacity 0.3s linear;
}

.slide-enter-to,
.slide-leave {
  opacity: 1;
}
</style>
